﻿<UserControl
	xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
	xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
	xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
	xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
	mc:Ignorable="d"
	x:Class="FreshTexture.UserControl3d"
	x:Name="UserControl"
	d:DesignWidth="531.344" d:DesignHeight="454.824">

	<Grid x:Name="LayoutRoot">
		<ListView ItemsSource="{Binding SourceTexturePack}">
			<ListView.ItemTemplate>
				<DataTemplate>
					<WrapPanel>
						<GroupBox Width="Auto" Height="Auto"
							DataContext="{Binding MainViewModel, Source={StaticResource Locator}}">
							<GroupBox.Triggers>
								<EventTrigger RoutedEvent="UIElement.MouseEnter">
									<BeginStoryboard>
										<Storyboard>
											<DoubleAnimation Storyboard.TargetName="myAngleRotation"
												Storyboard.TargetProperty="Angle"
												Duration="0:0:2" RepeatBehavior="Forever" To="359" />
											<DoubleAnimation Storyboard.TargetName="_camera"
												Storyboard.TargetProperty="FieldOfView"
												Duration="0:0:1" To="30">
												<DoubleAnimation.EasingFunction>
													<PowerEase Power="3" EasingMode="EaseIn" />
												</DoubleAnimation.EasingFunction>
											</DoubleAnimation>
										</Storyboard>
									</BeginStoryboard>
								</EventTrigger>
								<EventTrigger RoutedEvent="UIElement.MouseLeave">
									<BeginStoryboard>
										<Storyboard>
											<DoubleAnimation Storyboard.TargetName="myAngleRotation"
												Storyboard.TargetProperty="Angle"
												Duration="0:0:1" To="0" AccelerationRatio="1.0" />
											<DoubleAnimation Storyboard.TargetName="_camera"
												Storyboard.TargetProperty="FieldOfView"
												Duration="0:0:1" To="60" />
										</Storyboard>
									</BeginStoryboard>
								</EventTrigger>
							</GroupBox.Triggers>

							<Viewport3D Height="121" Width="141">
                                            <!--KAMERA-->
								<Viewport3D.Camera>
									<PerspectiveCamera x:Name="_camera" Position="2, 4, 6" LookDirection="-1, -2, -3"
										UpDirection="0, 1, 0"
										FieldOfView="60">
										<PerspectiveCamera.Transform>
											<Transform3DGroup>
												<RotateTransform3D>
													<RotateTransform3D.Rotation>
														<AxisAngleRotation3D x:Name="myAngleRotation" Axis="0 1 0" />
													</RotateTransform3D.Rotation>
												</RotateTransform3D>
											</Transform3DGroup>
										</PerspectiveCamera.Transform>
									</PerspectiveCamera>
								</Viewport3D.Camera>
								<ModelVisual3D>
									<ModelVisual3D.Content>
										<Model3DGroup>

                                                        <!--FACE #1-->
											<GeometryModel3D x:Name="FaceBottom">
												<GeometryModel3D.Geometry>
													<MeshGeometry3D Positions="-1,-1,-1 1,-1,-1 1,-1,1 -1,-1,1"
														TriangleIndices="0  1  2     2  3  0"
														TextureCoordinates="0,1 1,1 1,0 0,0" />
												</GeometryModel3D.Geometry>
												<GeometryModel3D.Material>
													<DiffuseMaterial>
														<DiffuseMaterial.Brush>
															<ImageBrush
																ImageSource="{Binding SourceTexturePack/FaceBottom, UpdateSourceTrigger=PropertyChanged}"
																Stretch="Fill" />
														</DiffuseMaterial.Brush>
													</DiffuseMaterial>
												</GeometryModel3D.Material>
											</GeometryModel3D>

                                                        <!--FACE #2-->
											<GeometryModel3D x:Name="FaceFront">
												<GeometryModel3D.Geometry>
													<MeshGeometry3D Positions="-1,-1,1 1,-1,1 1,1,1 -1,1,1"
														TriangleIndices="0  1  2     2  3  0"
														TextureCoordinates="0,1 1,1 1,0 0,0" />
												</GeometryModel3D.Geometry>
												<GeometryModel3D.Material>
													<DiffuseMaterial>
														<DiffuseMaterial.Brush>
															<ImageBrush
																ImageSource="{Binding SourceTexturePack/FaceFront, UpdateSourceTrigger=PropertyChanged}"
																Stretch="Fill" />
														</DiffuseMaterial.Brush>
													</DiffuseMaterial>
												</GeometryModel3D.Material>
											</GeometryModel3D>

                                                        <!--FACE #3-->
											<GeometryModel3D x:Name="FaceRight">
												<GeometryModel3D.Geometry>
													<MeshGeometry3D Positions="1,-1,1 1,-1,-1 1,1,-1 1,1,1"
														TriangleIndices="0  1  2     2  3  0"
														TextureCoordinates="0,1 1,1 1,0 0,0" />
												</GeometryModel3D.Geometry>
												<GeometryModel3D.Material>
													<DiffuseMaterial>
														<DiffuseMaterial.Brush>
															<ImageBrush
																ImageSource="{Binding SourceTexturePack/FaceRight, UpdateSourceTrigger=PropertyChanged}"
																Stretch="Fill" />
														</DiffuseMaterial.Brush>
													</DiffuseMaterial>
												</GeometryModel3D.Material>
											</GeometryModel3D>

                                                        <!--FACE #4-->
											<GeometryModel3D x:Name="FaceTop">
												<GeometryModel3D.Geometry>
													<MeshGeometry3D Positions="1,1,1 1,1,-1 -1,1,-1 -1,1,1"
														TriangleIndices="0  1  2     2  3  0"
														TextureCoordinates="0,0 0,1 1,1 1,0" />
												</GeometryModel3D.Geometry>
												<GeometryModel3D.Material>
													<DiffuseMaterial>
														<DiffuseMaterial.Brush>
															<ImageBrush
																ImageSource="{Binding SourceTexturePack/FaceTop, UpdateSourceTrigger=PropertyChanged}"
																Stretch="Fill" />
														</DiffuseMaterial.Brush>
													</DiffuseMaterial>
												</GeometryModel3D.Material>
											</GeometryModel3D>

                                                        <!--FACE #5-->
											<GeometryModel3D x:Name="FaceLeft">
												<GeometryModel3D.Geometry>
													<MeshGeometry3D Positions="-1,-1,1 -1,1,1 -1,1,-1 -1,-1,-1"
														TriangleIndices="0  1  2     2  3  0"
														TextureCoordinates="1,1 1,0 0,0 0,1" />
												</GeometryModel3D.Geometry>
												<GeometryModel3D.Material>
													<DiffuseMaterial>
														<DiffuseMaterial.Brush>
															<ImageBrush
																ImageSource="{Binding SourceTexturePack/FaceLeft, UpdateSourceTrigger=PropertyChanged}"
																Stretch="Fill" />
														</DiffuseMaterial.Brush>
													</DiffuseMaterial>
												</GeometryModel3D.Material>
											</GeometryModel3D>

                                                        <!--FACE #6-->
											<GeometryModel3D x:Name="FaceBack">
												<GeometryModel3D.Geometry>
													<MeshGeometry3D Positions="-1,-1,-1 -1,1,-1 1,1,-1 1,-1,-1"
														TriangleIndices="0  1  2     2  3  0"
														TextureCoordinates="1,1 1,0 0,0 0,1" />
												</GeometryModel3D.Geometry>
												<GeometryModel3D.Material>
													<DiffuseMaterial>
														<DiffuseMaterial.Brush>
															<ImageBrush
																ImageSource="{Binding SourceTexturePack/FaceBack, UpdateSourceTrigger=PropertyChanged}"
																Stretch="Fill" />
														</DiffuseMaterial.Brush>
													</DiffuseMaterial>
												</GeometryModel3D.Material>
											</GeometryModel3D>

											<AmbientLight Color="White" />
											<DirectionalLight Color="White" Direction="1,-2,-3" />
											<DirectionalLight Color="White" Direction="-1,2,3" />
										</Model3DGroup>
									</ModelVisual3D.Content>
								</ModelVisual3D>
							</Viewport3D>

						</GroupBox>
						<Label Content="{Binding IsSelected}" />
						<CheckBox IsChecked="{Binding IsSelected}" />
					</WrapPanel>
				</DataTemplate>
			</ListView.ItemTemplate>
		</ListView>
	</Grid>
</UserControl>